import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-01-08
 * Time: 16:40
 */
public class MyStack implements IStack{
    private int[] elem;
    private int usedSize;

    public MyStack() {
        elem=new int[10];
    }

    @Override
    public void push(int x) {
        if(full()){
            elem= Arrays.copyOf(elem,elem.length*2);
        }
        elem[usedSize]=x;
        usedSize++;
    }

    @Override
    public int pop() {
        if(empty()){
            throw new EmptyException("栈为空");
        }
        int old=elem[usedSize-1];
        usedSize--;
        return old;
    }

    @Override
    public int peek() {
        if(empty()){
            throw new EmptyException("栈为空");
        }
        return elem[usedSize-1];

    }

    @Override
    public int size() {
        return usedSize;
    }

    @Override
    public boolean empty() {
        return usedSize==0;
    }

    @Override
    public boolean full() {
        return usedSize==elem.length;
    }
}
